package restaurant.agents;

import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import restaurant.behaviours.booking.BookingConfirmBehaviour;
import restaurant.behaviours.booking.BookingRequestBehaviour;
import restaurant.core.Restaurant;

/**
 * Agent which assign the seats to every customer
 * @author Domenico Ventura
 *
 */
public class BookingAgent extends Agent {	
	private static final long serialVersionUID = -642689842037995738L;
	public Restaurant restaurant;
	private int score = 0;
	
	@Override
	protected void setup() {
		System.out.println("BookingAgent: Ristorante aperto!");
		
		this.restaurant = Restaurant.getInstance();
		
		DFAgentDescription agentDescription = new DFAgentDescription();
		agentDescription.setName(getAID());

		ServiceDescription serviceDescription = new ServiceDescription();
		serviceDescription.setType("booking");
		serviceDescription.setName("JADE-restaurant");

		agentDescription.addServices(serviceDescription);
		try {
			DFService.register(this, agentDescription);
		} catch (FIPAException e) {
			e.printStackTrace();
		}

		addBehaviour(new BookingRequestBehaviour(this));
		addBehaviour(new BookingConfirmBehaviour(this));
	}

	@Override
	protected void takeDown() {
		try {
			DFService.deregister(this);
		} catch (FIPAException e) {
			e.printStackTrace();
		}
		System.out.println("Agente Prenotazione " + this.getLocalName() + " terminato");
	}
	
	public void setScore(int score) {
		this.score = score;
		this.restaurant.bookingAgentScore = this.score;
	}
	
	public int getScore() {
		return score;
	}
}